/******************************************************************/
/*                                                                */
/*  Winpooch : Windows Watchdog                                   */
/*  Copyright (C) 2004-2005  Benoit Blanchon                      */
/*                                                                */
/*  This program is free software; you can redistribute it        */
/*  and/or modify it under the terms of the GNU General Public    */
/*  License as published by the Free Software Foundation; either  */
/*  version 2 of the License, or (at your option) any later       */
/*  version.                                                      */
/*                                                                */
/*  This program is distributed in the hope that it will be       */
/*  useful, but WITHOUT ANY WARRANTY; without even the implied    */
/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR       */
/*  PURPOSE.  See the GNU General Public License for more         */
/*  details.                                                      */
/*                                                                */
/*  You should have received a copy of the GNU General Public     */
/*  License along with this program; if not, write to the Free    */
/*  Software Foundation, Inc.,                                    */
/*  675 Mass Ave, Cambridge, MA 02139, USA.                       */
/*                                                                */
/******************************************************************/


/******************************************************************/
/* Build configuration                                            */
/******************************************************************/

#define TRACE_LEVEL	2 /* warning */


/******************************************************************/
/* Includes                                                       */
/******************************************************************/

// module's interface
#include "HookFile.h"

// standard headers
#include <tchar.h>

// project's headers
#include "Assert.h"
#include "Hooks.h"
#include "SpyDllInt.h"
#include "Trace.h"


/******************************************************************/
/* Exported function : CopyFileA (hooked)                         */
/******************************************************************/
/*
BOOL	WINAPI	Hook_CopyFileA	(LPCSTR lpExistingFileName,
				 LPCSTR lpNewFileName, 
				 BOOL bFailIfExists) 
{
  DWORD		nReaction ;
  TCHAR		*tszFileName ;  
  TCHAR		tszFilePath[MAX_PATH] ;

  TRACE ;

  //
  // get file path of existing file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpExistingFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpNewFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_CopyFileA (lpExistingFileName, lpNewFileName, bFailIfExists) ;
}
*/


/******************************************************************/
/* Exported function : CopyFileA (not hooked)                     */
/******************************************************************/
/*
BOOL	WINAPI	Real_CopyFileA	(LPCSTR lpExistingFileName,
				 LPCSTR lpNewFileName, 
				 BOOL bFailIfExists) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_COPYFILEA) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName, bFailIfExists) ;
}
*/


/******************************************************************/
/* Exported function : CopyFileW (hooked)                         */
/******************************************************************/
/*
BOOL	WINAPI	Hook_CopyFileW	(LPCWSTR lpExistingFileName,
				 LPCWSTR lpNewFileName, 
				 BOOL bFailIfExists) 
{
  DWORD		nReaction ;
  TCHAR		tszFilePath[MAX_PATH] ; 
 
  TRACE ;

  //
  // get file path of existing file
  //
  if( ! GetFullPathName (lpExistingFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpExistingFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  if( ! GetFullPathName (lpNewFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpNewFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_CopyFileW (lpExistingFileName, lpNewFileName, bFailIfExists) ;
}
*/

/******************************************************************/
/* Exported function : CopyFileW (not hooked)                     */
/******************************************************************/
/*
BOOL	WINAPI	Real_CopyFileW	(LPCWSTR lpExistingFileName,
				 LPCWSTR lpNewFileName, 
				 BOOL bFailIfExists) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_COPYFILEW) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName, bFailIfExists) ;
}
*/

/******************************************************************/
/* Exported function : CopyFileExA (hooked)                       */
/******************************************************************/
/*
BOOL WINAPI Hook_CopyFileExA (LPCSTR lpExistingFileName,
			      LPCSTR lpNewFileName,
			      LPPROGRESS_ROUTINE lpProgressRoutine,
			      LPVOID lpData,
			      LPBOOL pbCancel,
			      DWORD dwCopyFlags)
{
  DWORD		nReaction ;
  TCHAR		*tszFileName ;  
  TCHAR		tszFilePath[MAX_PATH] ;

  TRACE ;

  //
  // get file path of existing file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpExistingFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpNewFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_CopyFileExA (lpExistingFileName, lpNewFileName, lpProgressRoutine,
			   lpData, pbCancel, dwCopyFlags) ;
}
*/

/******************************************************************/
/* Exported function : CopyFileExA (not hooked)                   */
/******************************************************************/
/*
BOOL WINAPI Real_CopyFileExA (LPCSTR lpExistingFileName,
			      LPCSTR lpNewFileName,
			      LPPROGRESS_ROUTINE lpProgressRoutine,
			      LPVOID lpData,
			      LPBOOL pbCancel,
			      DWORD dwCopyFlags)
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_COPYFILEEXA) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName, lpProgressRoutine,
			 lpData, pbCancel, dwCopyFlags) ;
}
*/

/******************************************************************/
/* Exported function : CopyFileExA (hooked)                       */
/******************************************************************/
/*
BOOL WINAPI Hook_CopyFileExW (LPCWSTR lpExistingFileName,
			      LPCWSTR lpNewFileName,
			      LPPROGRESS_ROUTINE lpProgressRoutine,
			      LPVOID lpData,
			      LPBOOL pbCancel,
			      DWORD dwCopyFlags)
{
  DWORD		nReaction ;
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  if( ! GetFullPathName (lpExistingFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpExistingFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  if( ! GetFullPathName (lpNewFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpNewFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_CopyFileExW (lpExistingFileName, lpNewFileName, lpProgressRoutine,
			   lpData, pbCancel, dwCopyFlags) ;
}
*/

/******************************************************************/
/* Exported function : CopyFileExW (not hooked)                   */
/******************************************************************/
/*
BOOL WINAPI Real_CopyFileExW (LPCWSTR lpExistingFileName,
			      LPCWSTR lpNewFileName,
			      LPPROGRESS_ROUTINE lpProgressRoutine,
			      LPVOID lpData,
			      LPBOOL pbCancel,
			      DWORD dwCopyFlags)
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_COPYFILEEXW) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName, lpProgressRoutine,
			 lpData, pbCancel, dwCopyFlags) ;
}
*/


/******************************************************************/
/* Exported function : CreateFileA                                */
/******************************************************************/
/*
HANDLE WINAPI Hook_CreateFileA (LPCSTR	lpFileName,
				DWORD	dwDesiredAccess,
				DWORD	dwShareMode, 
				LPSECURITY_ATTRIBUTES lpSecurityAttributes,
				DWORD	dwCreationDistribution,
				DWORD	dwFlagsAndAttributes,
				HANDLE	hTemplateFile) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_CREATEFILEA) ;
  DWORD nReaction ;
  TCHAR *tszFileName ;  
  TCHAR szFilePath[MAX_PATH] ;
  
  TRACE ;

  // get file path
  tszFileName = SpyInt_AsciiToUnicode (lpFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, szFilePath, NULL) )
    _tcscpy (szFilePath, tszFileName) ;
  free (tszFileName) ;

  // log call  
  if( dwDesiredAccess & GENERIC_WRITE )
    nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), szFilePath) ;
  else
    nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), szFilePath) ;
  
  if( nReaction != RULE_ACCEPT ) return INVALID_HANDLE_VALUE ;
  
  // call real CreateFileA
  return (HANDLE)pfnStub (lpFileName, dwDesiredAccess, dwShareMode, 
			  lpSecurityAttributes, dwCreationDistribution,
			  dwFlagsAndAttributes, hTemplateFile) ;
}
*/


/******************************************************************/
/* Exported function : CreateFileW                                */
/******************************************************************/

HANDLE WINAPI Hook_CreateFileW (LPCWSTR	lpFileName,
				DWORD	dwDesiredAccess,
				DWORD	dwShareMode, 
				LPSECURITY_ATTRIBUTES lpSecurityAttributes,
				DWORD	dwCreationDistribution,
				DWORD	dwFlagsAndAttributes,
				HANDLE	hTemplateFile) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_CREATEFILEW) ;
  DWORD nReaction ;
  TCHAR szFilePath[MAX_PATH] ;
  
  TRACE ;

  // get file path
  if( ! GetFullPathName (lpFileName, MAX_PATH, szFilePath, NULL) )
    _tcscpy (szFilePath, lpFileName) ;

  // log call  
  if( dwDesiredAccess & GENERIC_WRITE )
    nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), szFilePath) ;
  else
    nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), szFilePath) ;

  if( nReaction != RULE_ACCEPT ) return INVALID_HANDLE_VALUE ;
  
  // call real CreateFileW
  return (HANDLE)pfnStub (lpFileName, dwDesiredAccess, dwShareMode, 
			  lpSecurityAttributes, dwCreationDistribution,
			  dwFlagsAndAttributes, hTemplateFile) ;
}


/******************************************************************/
/* Exported function : DeleteFileA (hooked)                       */
/******************************************************************/
/*
BOOL WINAPI Hook_DeleteFileA (LPCSTR lpFileName) 
{
  DWORD		nReaction ;
  TCHAR		*tszFileName ;  
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_DeleteFileA (lpFileName) ;
}
*/

/******************************************************************/
/* Exported function : CopyFileA (not hooked)                     */
/******************************************************************/
/*
BOOL WINAPI Real_DeleteFileA (LPCSTR lpFileName) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_DELETEFILEA) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpFileName) ;
}
*/

/******************************************************************/
/* Exported function : DeleteFileW (hooked)                       */
/******************************************************************/

BOOL WINAPI Hook_DeleteFileW (LPCWSTR lpFileName) 
{
  DWORD		nReaction ;
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  if( ! GetFullPathName (lpFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_DeleteFileW (lpFileName) ;
}


/******************************************************************/
/* Exported function : DeleteFileW (not hooked)                   */
/******************************************************************/

BOOL WINAPI Real_DeleteFileW (LPCTSTR lpFileName) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_DELETEFILEW) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpFileName) ;
}


/******************************************************************/
/* Exported function : MoveFileA (hooked)                         */
/******************************************************************/
/*
BOOL	WINAPI	Hook_MoveFileA	(LPCSTR lpExistingFileName,
				 LPCSTR lpNewFileName) 
{
  DWORD		nReaction ;
  TCHAR		*tszFileName ;  
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpExistingFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpNewFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_MoveFileA (lpExistingFileName, lpNewFileName) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileA (not hooked)                     */
/******************************************************************/
/*
BOOL WINAPI Real_MoveFileA (LPCSTR lpExistingFileName,
			    LPCSTR lpNewFileName) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_MOVEFILEA) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileW (hooked)                         */
/******************************************************************/
/*
BOOL	WINAPI	Hook_MoveFileW (LPCWSTR lpExistingFileName,
				LPCWSTR lpNewFileName) 
{
  DWORD		nReaction ;
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  if( ! GetFullPathName (lpExistingFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpExistingFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  if( ! GetFullPathName (lpNewFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpNewFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_MoveFileW (lpExistingFileName, lpNewFileName) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileW (not hooked)                     */
/******************************************************************/
/*
BOOL WINAPI Real_MoveFileW (LPCWSTR lpExistingFileName,
			    LPCWSTR lpNewFileName) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_MOVEFILEW) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileExA (hooked)                       */
/******************************************************************/
/*
BOOL WINAPI Hook_MoveFileExA (LPCSTR lpExistingFileName,
			      LPCSTR lpNewFileName,
			      DWORD dwFlags) 
{
  DWORD		nReaction ;
  TCHAR		*tszFileName ;  
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpExistingFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpNewFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_MoveFileExA (lpExistingFileName, lpNewFileName, dwFlags) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileExA (not hooked)                     */
/******************************************************************/
/*
BOOL WINAPI Real_MoveFileExA (LPCSTR lpExistingFileName,
			      LPCSTR lpNewFileName,
			      DWORD dwFlags) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_MOVEFILEEXA) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName, dwFlags) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileExW (hooked)                       */
/******************************************************************/
/*
BOOL	WINAPI	Hook_MoveFileExW (LPCWSTR lpExistingFileName,
				  LPCWSTR lpNewFileName,
				  DWORD dwFlags) 
{
  DWORD		nReaction ;
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  if( ! GetFullPathName (lpExistingFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpExistingFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  if( ! GetFullPathName (lpNewFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpNewFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_MoveFileExW (lpExistingFileName, lpNewFileName, dwFlags) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileExW (not hooked)                   */
/******************************************************************/
/*
BOOL WINAPI Real_MoveFileExW (LPCWSTR lpExistingFileName,
			      LPCWSTR lpNewFileName,
			      DWORD dwFlags) 
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_MOVEFILEEXW) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName, dwFlags) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileWithProgressA  (hooked)            */
/******************************************************************/
/*
BOOL WINAPI Hook_MoveFileWithProgressA (LPCSTR lpExistingFileName,
					LPCSTR lpNewFileName,
					LPPROGRESS_ROUTINE lpProgressRoutine,
					LPVOID lpData,
					DWORD dwFlags)
{
  DWORD		nReaction ;
  TCHAR		*tszFileName ;  
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpExistingFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  tszFileName = SpyInt_AsciiToUnicode (lpNewFileName) ;
  if( ! GetFullPathName (tszFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, tszFileName) ;
  free (tszFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_MoveFileWithProgressA (lpExistingFileName, lpNewFileName,
				     lpProgressRoutine, lpData, dwFlags) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileWithProgressA (not hooked)         */
/******************************************************************/
/*
BOOL WINAPI Real_MoveFileWithProgressA (LPCSTR lpExistingFileName,
			    LPCSTR lpNewFileName,
			    LPPROGRESS_ROUTINE lpProgressRoutine,
			    LPVOID lpData,
			    DWORD dwFlags)
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_MOVEFILEWITHPROGRESSA) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName,
			 lpProgressRoutine, lpData, dwFlags) ;
}
*/

/******************************************************************/
/* Exported function : MoveFileWithProgressW (hooked)             */
/******************************************************************/

BOOL	WINAPI	Hook_MoveFileWithProgressW (LPCWSTR lpExistingFileName,
				LPCWSTR lpNewFileName,
				LPPROGRESS_ROUTINE lpProgressRoutine,
				LPVOID lpData,
				DWORD dwFlags)
{
  DWORD		nReaction ;
  TCHAR		tszFilePath[MAX_PATH] ;
  
  TRACE ;

  //
  // get file path of existing file
  //
  if( ! GetFullPathName (lpExistingFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpExistingFileName) ;

  //
  // check if read is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_READ, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  //
  // get file path of new file
  //
  if( ! GetFullPathName (lpNewFileName, MAX_PATH, tszFilePath, NULL) )
    _tcscpy (tszFilePath, lpNewFileName) ;

  //
  // check if write is allowed 
  //
  nReaction = SpyInt_CatchCall (REASON_FILE_WRITE, TEXT("s"), tszFilePath) ;
  switch( nReaction )
    {
    case RULE_REJECT:
      SetLastError (ERROR_ACCESS_DENIED) ;
      return FALSE ;
    case RULE_FEIGN:
      SetLastError (ERROR_SUCCESS) ;
      return TRUE ;
    }

  // call real API function
  return Real_MoveFileWithProgressW (lpExistingFileName, lpNewFileName,
				     lpProgressRoutine, lpData, dwFlags) ;
}


/******************************************************************/
/* Exported function : MoveFileWithProgressW (not hooked)         */
/******************************************************************/

BOOL WINAPI Real_MoveFileWithProgressW (LPCWSTR lpExistingFileName,
					LPCWSTR lpNewFileName,
					LPPROGRESS_ROUTINE lpProgressRoutine,
					LPVOID lpData,
					DWORD dwFlags)
{
  PROC	pfnStub = Hooks_GetStubAddress (HOOKS_MOVEFILEWITHPROGRESSW) ;
  
  TRACE ;
  
  ASSERT (pfnStub!=NULL) ;
  
  return (BOOL) pfnStub (lpExistingFileName, lpNewFileName,
			 lpProgressRoutine, lpData, dwFlags) ;
}
